#include "junix.h"

int main(int argc, char **argv)
{
	char buf[1024];
	if(NULL==tmpnam(buf)) //dangerous
		fprintf(stderr,"error");

	printf("%s\n",buf);

	int fd;
	if((fd=mkstemp("junixXXXXXX"))==-1)
		err_quit("mkstemp");

	if( write(fd,"UNIX",4) != 4)
		err_sys("write");

	if(lseek(fd,0,SEEK_SET)==-1)
		err_sys("lseek");

	ssize_t sz;
	if( (sz=read(fd,buf,1024)) > 0)
	{
		buf[sz]='\0';
		fputs(buf,stdout);
	}

	if(sz==-1)
		err_sys("read");

	if(close(fd)==-1)
		err_sys("close");

	return 0;
}

